package com.aaa.controller;

import com.aaa.dao.IBookDao;
import com.aaa.dao.ITypeDao;
import com.aaa.dao.impl.IBookDaoImpl;
import com.aaa.dao.impl.ITypeDaoImpl;
import com.aaa.entity.Book;
import com.aaa.utils.LayTab;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet("/type/*")
public class TypeController extends HttpServlet {

    private ITypeDao typeDao = new ITypeDaoImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String uri = req.getRequestURI();
        String[] split = uri.split("/");
        String s = split[split.length - 1];
        switch (s){
            case "findAllType":
                findAllType(req,resp);
                break;

        }
    }

    /**
     * 查询所有的书籍类型信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    protected void findAllType(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Map> types = typeDao.findAllType();
        String s = JSON.toJSONString(types);
        resp.getWriter().write(s);
    }


}
